package com.dingreading.cloud.ssxcx.service.impl;

import com.dingreading.cloud.ssxcx.entity.XcxAnswersPandect;
import com.dingreading.cloud.ssxcx.entity.table.XcxAnswersPandectTableDef;
import com.dingreading.cloud.ssxcx.mapper.XcxAnswersPandectMapper;
import com.dingreading.cloud.ssxcx.service.XcxAnswersPandectService;
import com.mybatisflex.core.query.QueryCondition;
import com.mybatisflex.core.query.QueryWrapper;
import org.springframework.stereotype.Service;

/**
 * 小程序学生答题记录总览表 服务层实现。
 *
 * @author EDY
 * @since 2025-08-25
 */
@Service
public class XcxAnswersPandectServiceImpl extends BaseServiceImpl<XcxAnswersPandectMapper, XcxAnswersPandect, XcxAnswersPandectTableDef> implements XcxAnswersPandectService {

    @Override
    protected XcxAnswersPandectTableDef getTable() {
        return XcxAnswersPandectTableDef.xcxAnswersPandect;
    }

    @Override
    public XcxAnswersPandect getLate(String studentUid, String subjectLessonUid) {
        QueryCondition condition = QueryCondition.createEmpty()
                .and(table.studentUid.eq(studentUid))
                .and(table.subjectLessonUid.eq(subjectLessonUid))
                .and(table.enabled.eq(1));

        QueryWrapper queryWrapper = QueryWrapper.create()
                .select(table.isAllCorrect)
                .where(condition)
                .orderBy(table.id.desc())
                .limit(1);
        return getMapper().selectOneByQuery(queryWrapper);
    }
}
